/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VistaListaVentas.java
 *
 * Created on 20-ene-2012, 17:53:21
 */
package invsys.Vistas;

import invsys.Controladores.ControlCliente;
import invsys.Controladores.ControlDetalleVenta;
import invsys.Controladores.ControlUsuario;
import invsys.Controladores.ControlVenta;
import invsys.Modelo.Cliente;
import invsys.Modelo.DetalleVenta;
import invsys.Modelo.Producto;
import invsys.Modelo.Usuario;
import invsys.Modelo.Venta;
import invsys.Utilidades.ManejadorBaseDatos;
import invsys.Utilidades.ValidarorVistas;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.xml.bind.annotation.XmlElement.DEFAULT;

/**
 *
 * @author dell
 */
public class VistaListaVentas extends javax.swing.JDialog {
DefaultTableModel dtm1= new DefaultTableModel();
DefaultListModel dlm = new DefaultListModel();
DefaultListModel dlm1 = new DefaultListModel();
DefaultTableModel dtm2= new DefaultTableModel();
ValidarorVistas vistas= new ValidarorVistas();
    /** Creates new form VistaListaVentas */
    public VistaListaVentas(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.setLocationRelativeTo(this);
        jPanel3.setVisible(false);
     }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        busqueda = new javax.swing.ButtonGroup();
        busquedafecha = new javax.swing.ButtonGroup();
        Abono = new javax.swing.JDialog();
        PanelDetalles = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jPanel9 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        productos = new org.jdesktop.swingx.JXTable(dtm2);
        facturacredito = new javax.swing.JTextField();
        fechacredito = new javax.swing.JTextField();
        saldoact = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        iva = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        descuento = new javax.swing.JTextField();
        idcliente = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        NombreCliente = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        txtcredito = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        tipo = new javax.swing.JTextField();
        opcion = new javax.swing.JPopupMenu();
        Detalles = new javax.swing.JMenuItem();
        jPanel4 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        opT = new javax.swing.JCheckBox();
        opU = new javax.swing.JCheckBox();
        opC = new javax.swing.JCheckBox();
        jXPanel1 = new org.jdesktop.swingx.JXPanel();
        jPanel7 = new javax.swing.JPanel();
        opD = new javax.swing.JRadioButton();
        opM = new javax.swing.JRadioButton();
        opA = new javax.swing.JRadioButton();
        fecha = new com.toedter.calendar.JCalendar();
        jPanel3 = new javax.swing.JPanel();
        cb_buscarC = new javax.swing.JComboBox();
        txt_buscarC = new javax.swing.JTextField();
        jScrollPane3 = new javax.swing.JScrollPane();
        ListaClientes = new javax.swing.JList(dlm);
        txt_nombreC = new javax.swing.JLabel();
        txt_DireccionC = new javax.swing.JLabel();
        txt_telefonoC = new javax.swing.JLabel();
        txt_mailC = new javax.swing.JLabel();
        opN = new javax.swing.JRadioButton();
        bt_Busccar = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        listaventas = new org.jdesktop.swingx.JXTable(dtm1);
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        mensaje = new javax.swing.JLabel();
        cantidad = new javax.swing.JTextField();

        PanelDetalles.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos Del Credito"));

        jLabel5.setText("Factura:");

        jLabel6.setText("Fecha:");

        jPanel9.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        dtm2.addColumn("Codigo");
        dtm2.addColumn("Nombre");
        dtm2.addColumn("Descripcion");
        dtm2.addColumn("Precio");
        dtm2.addColumn("Cantidad");
        dtm2.addColumn("Costo");
        dtm2.addColumn("Cantidad Anterior");
        dtm2.addColumn("Cantidad Restante");
        productos.setEditable(false);
        productos.setEnabled(false);
        jScrollPane2.setViewportView(productos);

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 567, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
                .addContainerGap())
        );

        facturacredito.setEditable(false);

        fechacredito.setEditable(false);

        saldoact.setEditable(false);
        saldoact.setFont(new java.awt.Font("Agency FB", 1, 14)); // NOI18N
        saldoact.setForeground(new java.awt.Color(51, 102, 0));
        saldoact.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        saldoact.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Total De La Venta", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 102, 0)));

        jLabel10.setText("Iva:");

        iva.setEditable(false);

        jLabel11.setText("Descuento:");

        descuento.setEditable(false);

        idcliente.setEditable(false);

        jLabel12.setText("Identificacion:");

        jLabel13.setText("Nombre:");

        NombreCliente.setEditable(false);

        jLabel14.setText("Credito:");

        txtcredito.setEditable(false);

        jLabel15.setText("%");

        jButton3.setText("Salir");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        tipo.setEditable(false);
        tipo.setFont(new java.awt.Font("Agency FB", 1, 14)); // NOI18N
        tipo.setForeground(new java.awt.Color(255, 51, 51));
        tipo.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tipo.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Tipo De Venta", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 153)));
        tipo.setCaretColor(new java.awt.Color(255, 0, 0));

        javax.swing.GroupLayout PanelDetallesLayout = new javax.swing.GroupLayout(PanelDetalles);
        PanelDetalles.setLayout(PanelDetallesLayout);
        PanelDetallesLayout.setHorizontalGroup(
            PanelDetallesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelDetallesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PanelDetallesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(PanelDetallesLayout.createSequentialGroup()
                        .addComponent(tipo, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 272, Short.MAX_VALUE)
                        .addComponent(jButton3))
                    .addComponent(jPanel9, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(PanelDetallesLayout.createSequentialGroup()
                        .addGroup(PanelDetallesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel12)
                            .addComponent(jLabel13)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(PanelDetallesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(idcliente, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE)
                            .addComponent(NombreCliente, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE)
                            .addComponent(fechacredito, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE))
                        .addGap(4, 4, 4)
                        .addGroup(PanelDetallesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel10)
                            .addComponent(jLabel14))
                        .addGap(14, 14, 14)
                        .addGroup(PanelDetallesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, PanelDetallesLayout.createSequentialGroup()
                                .addComponent(iva, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(descuento, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(txtcredito, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(facturacredito, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(saldoact, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)))
                .addContainerGap())
        );
        PanelDetallesLayout.setVerticalGroup(
            PanelDetallesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelDetallesLayout.createSequentialGroup()
                .addGroup(PanelDetallesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(PanelDetallesLayout.createSequentialGroup()
                        .addGroup(PanelDetallesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel12)
                            .addComponent(idcliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5)
                            .addComponent(facturacredito, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(PanelDetallesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(PanelDetallesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(NombreCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel10)
                                .addComponent(iva, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(descuento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel11))
                            .addComponent(jLabel13)
                            .addComponent(jLabel15))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(PanelDetallesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtcredito, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(PanelDetallesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(fechacredito, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel14))
                            .addComponent(jLabel6)))
                    .addComponent(saldoact, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PanelDetallesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton3)
                    .addComponent(tipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout AbonoLayout = new javax.swing.GroupLayout(Abono.getContentPane());
        Abono.getContentPane().setLayout(AbonoLayout);
        AbonoLayout.setHorizontalGroup(
            AbonoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AbonoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(PanelDetalles, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        AbonoLayout.setVerticalGroup(
            AbonoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AbonoLayout.createSequentialGroup()
                .addComponent(PanelDetalles, javax.swing.GroupLayout.PREFERRED_SIZE, 352, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        Detalles.setText("jMenuItem1");
        Detalles.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DetallesActionPerformed(evt);
            }
        });
        opcion.add(Detalles);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Control De Ventas", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Agency FB", 1, 18))); // NOI18N

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Buscar"));

        busqueda.add(opT);
        opT.setSelected(true);
        opT.setText("Todos");
        opT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                opTActionPerformed(evt);
            }
        });

        busqueda.add(opU);
        opU.setText("Usuario");
        opU.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                opUActionPerformed(evt);
            }
        });

        busqueda.add(opC);
        opC.setText("Cliente");
        opC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                opCActionPerformed(evt);
            }
        });

        jXPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("opciones De Busqueda"));

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(" Fecha Por:"));

        busquedafecha.add(opD);
        opD.setSelected(true);
        opD.setText("Diarias");
        opD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                opDActionPerformed(evt);
            }
        });

        busquedafecha.add(opM);
        opM.setText("Mensual");
        opM.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                opMActionPerformed(evt);
            }
        });

        busquedafecha.add(opA);
        opA.setText("Anual");
        opA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                opAActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(opM)
                    .addComponent(opA)
                    .addComponent(opD))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addComponent(opD)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(opM)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(opA))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos de:"));

        cb_buscarC.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Nombre:", "Identificacion:" }));

        txt_buscarC.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txt_buscarCKeyReleased(evt);
            }
        });

        ListaClientes.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ListaClientesMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(ListaClientes);

        txt_nombreC.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        txt_nombreC.setText("Nombre Completo");

        txt_DireccionC.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        txt_DireccionC.setText("Direcion");

        txt_telefonoC.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        txt_telefonoC.setText("telefono");

        txt_mailC.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        txt_mailC.setText("ID");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(cb_buscarC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txt_buscarC, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE))
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE)
                    .addComponent(txt_nombreC, javax.swing.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE)
                    .addComponent(txt_mailC, javax.swing.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE)
                    .addComponent(txt_telefonoC, javax.swing.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE)
                    .addComponent(txt_DireccionC, javax.swing.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cb_buscarC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txt_buscarC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(15, 15, 15)
                .addComponent(txt_mailC)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txt_nombreC)
                .addGap(13, 13, 13)
                .addComponent(txt_DireccionC)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(txt_telefonoC)
                .addContainerGap())
        );

        busquedafecha.add(opN);
        opN.setText("No Fecha");
        opN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                opNActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jXPanel1Layout = new javax.swing.GroupLayout(jXPanel1);
        jXPanel1.setLayout(jXPanel1Layout);
        jXPanel1Layout.setHorizontalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addComponent(fecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jXPanel1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(opN)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jXPanel1Layout.setVerticalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(fecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jXPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(opN)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        bt_Busccar.setText("Buscar");
        bt_Busccar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_BusccarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(opT)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(opC)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(opU))
                    .addComponent(jXPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(138, Short.MAX_VALUE)
                .addComponent(bt_Busccar)
                .addGap(108, 108, 108))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(opT)
                    .addComponent(opC)
                    .addComponent(opU))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jXPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bt_Busccar))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Ventas"));

        dtm1.addColumn("Factura");
        dtm1.addColumn("Fecha");
        dtm1.addColumn("Cliente");
        dtm1.addColumn("Monto");
        dtm1.addColumn("Responsable");
        dtm1.addColumn("Tipo");
        listaventas.setComponentPopupMenu(opcion);
        jScrollPane1.setViewportView(listaventas);

        jButton1.setText("Salir");

        jButton2.setText("Detalles");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        mensaje.setForeground(new java.awt.Color(255, 51, 0));

        cantidad.setFont(new java.awt.Font("Tahoma", 1, 18));
        cantidad.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        cantidad.setText("0");
        cantidad.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), "Cantidad", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 512, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jButton2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 302, Short.MAX_VALUE)
                                .addComponent(jButton1))
                            .addComponent(mensaje, javax.swing.GroupLayout.PREFERRED_SIZE, 426, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 393, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton2)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(cantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton1))))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(399, 399, 399)
                .addComponent(mensaje, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(32, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void opTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_opTActionPerformed
           jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("No se Registraran Datos:"));
             bt_Busccar.setEnabled(true);
             Limpiar();
            dlm.removeAllElements();
            jPanel3.setVisible(false);
            txt_buscarC.setText("");
              // TODO add your handling code here:
    }//GEN-LAST:event_opTActionPerformed

    private void opCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_opCActionPerformed
            jPanel3.setVisible(true);
            bt_Busccar.setEnabled(false);
            jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos del Cliente:"));
            Limpiar();
            dlm.removeAllElements();
            txt_buscarC.setText("");
             opN.setVisible(true);
        // TODO add your handling code here:
    }//GEN-LAST:event_opCActionPerformed

    private void opUActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_opUActionPerformed
            jPanel3.setVisible(true);
            bt_Busccar.setEnabled(false);
            jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos del Ususario:"));
            Limpiar();
            dlm.removeAllElements();
            txt_buscarC.setText("");
             opN.setVisible(true);
            // TODO add your handling code here:
    }//GEN-LAST:event_opUActionPerformed

    private void txt_buscarCKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_buscarCKeyReleased
        try {
            if(opC.isSelected()){
            dlm.removeAllElements();
                       String item = cb_buscarC.getSelectedItem().toString();
                       
                       
                       ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
                       mbd.conectar();

                       if (item.equals("Identificacion:")) {
                           ControlCliente.con= mbd.getConexion();
                           ControlCliente.listarCliente1("SELECT * FROM clientes  WHERE id LIKE '%"+txt_buscarC.getText()+"%'");
                       Iterator iter= ControlCliente.getCliente().iterator();
                       while(iter.hasNext()){
                       Cliente emp= (Cliente)iter.next();
                        String fila =emp.getId()+"-"+emp.getNombre()+"--"+emp.getApellido();
                       dlm.addElement(fila);
                           }
                       } else {
                       if(item.equals("Nombre:")){
                           ControlCliente.con= mbd.getConexion();
                           ControlCliente.listarCliente1("SELECT * FROM clientes  WHERE nombre LIKE '%"+txt_buscarC.getText()+"%'");
                       Iterator iter= ControlCliente.getCliente().iterator();
                       while(iter.hasNext()){
                       Cliente emp= (Cliente)iter.next();
                        String fila =emp.getId()+"-"+emp.getNombre()+"--"+emp.getApellido();
                       dlm.addElement(fila);
                       }
                       }
                            }
            }else{
                 dlm.removeAllElements();
                       String item = cb_buscarC.getSelectedItem().toString();
                       
                       
                       ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
                       mbd.conectar();

                       if (item.equals("Identificacion:")) {
                           ControlUsuario.con= mbd.getConexion();
                           ControlUsuario.listarUsuario1("SELECT * FROM usuarios  WHERE id LIKE '%"+txt_buscarC.getText()+"%'");
                       Iterator iter= ControlUsuario.getUsuario().iterator();
                       while(iter.hasNext()){
                       Usuario emp= (Usuario)iter.next();
                        String fila =emp.getId()+"-"+emp.getNombre()+"--"+emp.getApellido();
                       dlm.addElement(fila);
                           }
                       } else {
                       if(item.equals("Nombre:")){
                             ControlUsuario.con= mbd.getConexion();
                           ControlUsuario.listarUsuario1("SELECT * FROM usuarios  WHERE nombre LIKE '%"+txt_buscarC.getText()+"%'");
                       Iterator iter= ControlUsuario.getUsuario().iterator();
                       while(iter.hasNext()){
                       Usuario emp= (Usuario)iter.next();
                        String fila =emp.getId()+"-"+emp.getNombre()+"--"+emp.getApellido();
                       dlm.addElement(fila);
                       }
                       }
                            }
            
            }
                   // TODO add your handling code here:
        } catch (Exception ex) {
            Logger.getLogger(VistaListaVentas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_txt_buscarCKeyReleased

    private void ListaClientesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ListaClientesMouseClicked
AnadirAction();
// TODO add your handling code here:
    }//GEN-LAST:event_ListaClientesMouseClicked

    private void bt_BusccarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_BusccarActionPerformed

 SimpleDateFormat fechaForma = new SimpleDateFormat("dd/MM/yyyy");
    SimpleDateFormat fechaForma1 = new SimpleDateFormat("MM/yyyy");
    SimpleDateFormat fechaForma2 = new SimpleDateFormat("yyyy");
    
    String FechaDia=fechaForma.format(fecha.getDate());
    String FechaMes=fechaForma1.format(fecha.getDate());
    String FechaAno=fechaForma2.format(fecha.getDate());
if(opT.isSelected()){
       if(opM.isSelected()){
   ListarVentaMes(FechaDia,FechaMes);
   cantidad.setText(dtm1.getRowCount()+"");
       }else
        if(opD.isSelected()){
            ListarVentaDia(FechaDia);
            cantidad.setText(dtm1.getRowCount()+"");
        } else
            if(opA.isSelected()){
            ListarVentaAno(FechaDia,FechaAno);
            cantidad.setText(dtm1.getRowCount()+"");
            }else
        if(opN.isSelected()){
                ListarVenta();
                cantidad.setText(dtm1.getRowCount()+"");}
}else
if(opC.isSelected()){        
            if(opM.isSelected()){
   ListarVentaMesCliente(FechaDia,FechaMes);
   cantidad.setText(dtm1.getRowCount()+"");
            }else
        if(opD.isSelected()){
            ListarVentaDiaCliente(FechaDia);
            cantidad.setText(dtm1.getRowCount()+"");
        }else
            if(opA.isSelected()){
                ListarVentaAnoCliente(FechaDia,FechaAno);
                cantidad.setText(dtm1.getRowCount()+"");
            }else
            if(opN.isSelected()){
                ListarVentaCliente(txt_mailC.getText());
                cantidad.setText(dtm1.getRowCount()+"");}
     }else
           if(opU.isSelected())        
           {
  if(opM.isSelected()){
   ListarVentaMesUsuario(FechaDia,FechaMes);
   cantidad.setText(dtm1.getRowCount()+"");
   } else
        if(opD.isSelected()){
            ListarVentaDiaUsuario(FechaDia);
            cantidad.setText(dtm1.getRowCount()+"");
        }else
            if(opA.isSelected()){
                ListarVentaAnoUsuario(FechaDia,FechaAno);
            cantidad.setText(dtm1.getRowCount()+"");
            }else
            if(opN.isSelected()){
                ListarVentaUsuario(txt_mailC.getText());
                cantidad.setText(dtm1.getRowCount()+"");
           }
           
   
           }

        // TODO add your handling code here:
    }//GEN-LAST:event_bt_BusccarActionPerformed

    private void opDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_opDActionPerformed
bt_Busccar.setEnabled(true); 
// TODO add your handling code here:
    }//GEN-LAST:event_opDActionPerformed

    private void opMActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_opMActionPerformed
bt_Busccar.setEnabled(true); 
// TODO add your handling code here:
    }//GEN-LAST:event_opMActionPerformed

    private void opAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_opAActionPerformed
bt_Busccar.setEnabled(true); 
// TODO add your handling code here:
    }//GEN-LAST:event_opAActionPerformed

    private void opNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_opNActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_opNActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
avririventana();  
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
Abono.dispose();
// TODO add your handling code here:
    }//GEN-LAST:event_jButton3ActionPerformed

    private void DetallesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DetallesActionPerformed
avririventana();
// TODO add your handling code here:
    }//GEN-LAST:event_DetallesActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
    

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                VistaListaVentas dialog = new VistaListaVentas(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDialog Abono;
    private javax.swing.JMenuItem Detalles;
    private javax.swing.JList ListaClientes;
    private javax.swing.JTextField NombreCliente;
    public static javax.swing.JPanel PanelDetalles;
    private javax.swing.JButton bt_Busccar;
    private javax.swing.ButtonGroup busqueda;
    private javax.swing.ButtonGroup busquedafecha;
    private javax.swing.JTextField cantidad;
    private javax.swing.JComboBox cb_buscarC;
    private javax.swing.JTextField descuento;
    private javax.swing.JTextField facturacredito;
    private com.toedter.calendar.JCalendar fecha;
    private javax.swing.JTextField fechacredito;
    private javax.swing.JTextField idcliente;
    private javax.swing.JTextField iva;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private org.jdesktop.swingx.JXPanel jXPanel1;
    private org.jdesktop.swingx.JXTable listaventas;
    private javax.swing.JLabel mensaje;
    private javax.swing.JRadioButton opA;
    private javax.swing.JCheckBox opC;
    private javax.swing.JRadioButton opD;
    private javax.swing.JRadioButton opM;
    private javax.swing.JRadioButton opN;
    private javax.swing.JCheckBox opT;
    private javax.swing.JCheckBox opU;
    private javax.swing.JPopupMenu opcion;
    public static org.jdesktop.swingx.JXTable productos;
    private javax.swing.JTextField saldoact;
    private javax.swing.JTextField tipo;
    private javax.swing.JLabel txt_DireccionC;
    private javax.swing.JTextField txt_buscarC;
    private javax.swing.JLabel txt_mailC;
    private javax.swing.JLabel txt_nombreC;
    private javax.swing.JLabel txt_telefonoC;
    private javax.swing.JTextField txtcredito;
    // End of variables declaration//GEN-END:variables
  private  void AnadirAction() {
             int x = ListaClientes.getSelectedIndex();
           if(x < 0){
            JOptionPane.showMessageDialog(null, "Selecione primero el empleado ");
        }else{

            try {
                String empleado = ListaClientes.getSelectedValue().toString();
                StringTokenizer st = new StringTokenizer(empleado, "-");
                String id = st.nextToken();
                StringTokenizer st1 = new StringTokenizer(empleado, id + "-" + "--");
                String nombre = st1.nextToken().trim();
                Cliente Cli;
                Usuario usu;
                String item = cb_buscarC.getSelectedItem().toString();
    
                if(item.equals("Identificacion:")){
                    Cli = ControlCliente.BuscarClienteid(id);
                    usu = ControlUsuario.BuscarUsuario(id);
                txt_buscarC.setText(id);
                
                }else{
                     Cli = ControlCliente.BuscarClientenombre(nombre);
                     usu =ControlUsuario.BuscarUsuarionombre(nombre);
                  txt_buscarC.setText(nombre);
                  
                }
             if(Cli != null){
            bt_Busccar.setEnabled(true);
            txt_nombreC.setText(vistas.convertirMayuscula(Cli.getNombre()+" "+Cli.getApellido()));
            txt_DireccionC.setText(Cli.getDireccion());
            txt_telefonoC.setText(Cli.getTelefono());
            txt_mailC.setText(Cli.getId());
            }else{
              bt_Busccar.setEnabled(true);
            txt_nombreC.setText(vistas.convertirMayuscula(usu.getNombre()+" "+usu.getApellido()));
            txt_DireccionC.setText(usu.getDireccion());
            txt_telefonoC.setText(usu.getTelefono());
            txt_mailC.setText(usu.getId());   
             }
        } catch (Exception ex) {
            Logger.getLogger(VistaListaVentas.class.getName()).log(Level.SEVERE, null, ex);
        }
      }

    }
  
   
    private void ListarVentaDia(String fecha) {
        try {
            jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Todas Las Ventas Del Dia: "+fecha+"")); 
            dtm1.setNumRows(0);
         ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
         mbd.conectar();          
         ControlVenta.con=mbd.getConexion();
         ControlVenta.listarVenta1("SELECT *FROM ventas WHERE fecha= '"+fecha+"'");
         Iterator iter1= ControlVenta.getVenta().iterator()
                 ;
         while(iter1.hasNext()){
            Venta ven = (Venta) iter1.next();
            String[] fila = {ven.getNumero(),ven.getFecha(),ven.getCliente().getNombre(),(int)ven.getTotal()+"", ven.getUsuario().getNombre(),ven.getTipoPago()};
            dtm1.addRow(fila);
            
    
         }if(dtm1.getRowCount()==0){
         mensaje.setText("No Se ayó Resultado  En La Busqueda para la fecha"+fecha+"");
         }else{
             mensaje.setText("");
         }
         
        } catch (Exception ex) {
            Logger.getLogger(VistaListaVentas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    private void ListarVentaMes(String fecha,String fechaMes) {
        try {
         jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Todas Las Ventas Del Mes: "+fechaMes+""));  
         dtm1.setNumRows(0);
         ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
         mbd.conectar();          
         ControlVenta.con=mbd.getConexion();
         ControlVenta.listarVenta1("SELECT *FROM ventas  ");
         Iterator iter1= ControlVenta.getVenta().iterator();
         while(iter1.hasNext()){
            Venta ven = (Venta) iter1.next();
            StringTokenizer feMes=new StringTokenizer(ven.getFecha(),"/ ");
            String fDia=feMes.nextToken().toString();
            String fMes=feMes.nextToken().toString();
            String fAno=feMes.nextToken().toString();
            String FechaMes=fMes+"/"+fAno;
            if(FechaMes.equals(fechaMes)){
                    String[] fila = {ven.getNumero(),ven.getFecha(),ven.getCliente().getNombre(),(int)ven.getTotal()+"", ven.getUsuario().getNombre(),ven.getTipoPago()};
            dtm1.addRow(fila);
            }
    
         }if(dtm1.getRowCount()==0){
         mensaje.setText("No Se ayó Resultado  En La Busqueda Las Ventas Del Mes: "+fechaMes+"");
         }else{
             mensaje.setText("");
         }
        } catch (Exception ex) {
            Logger.getLogger(VistaListaVentas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    private void ListarVentaAno(String fecha,String fechaAno) {
        try {
            jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Todas Las Ventas Del ano: "+fechaAno+"")); 
            dtm1.setNumRows(0);
         ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
         mbd.conectar();          
         ControlVenta.con=mbd.getConexion();
         ControlVenta.listarVenta1("SELECT *FROM ventas ");
         Iterator iter1= ControlVenta.getVenta().iterator();
         while(iter1.hasNext()){
            Venta ven = (Venta) iter1.next();
            StringTokenizer feMes=new StringTokenizer(ven.getFecha(),"/ ");
            String fDia=feMes.nextToken().toString();
            String fMes=feMes.nextToken().toString();
            String fAno=feMes.nextToken().toString();
            String FechaMes=fAno;
            if(FechaMes.equals(fechaAno)){
                    String[] fila = {ven.getNumero(),ven.getFecha(),ven.getCliente().getNombre(),(int)ven.getTotal()+"", ven.getUsuario().getNombre(),ven.getTipoPago()};
            dtm1.addRow(fila);
            }
    
         }if(dtm1.getRowCount()==0){
         mensaje.setText("No Se ayó Resultado  En La Busqueda Para Las Ventas Del ano: "+fechaAno+"");
         }else{
             mensaje.setText("");
         }
        } catch (Exception ex) {
            Logger.getLogger(VistaListaVentas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    private void ListarVentaDiaCliente(String fecha) {
        try {
            
            dtm1.setNumRows(0);
         ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
         mbd.conectar();          
         ControlVenta.con=mbd.getConexion();
         ControlVenta.listarVenta1("SELECT *FROM ventas WHERE fecha= '"+fecha+"' and cliente='"+txt_mailC.getText()+"'");
         Iterator iter1= ControlVenta.getVenta().iterator()
                 ;
         while(iter1.hasNext()){
            Venta ven = (Venta) iter1.next();
            jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Todas Las Ventas a: "+vistas.convertirMayuscula(ven.getCliente().getNombre()+""+ven.getCliente().getApellido())+" Del Dia: "+fecha+""));
            String[] fila = {ven.getNumero(),ven.getFecha(),ven.getCliente().getNombre(),(int)ven.getTotal()+"", ven.getUsuario().getNombre(),ven.getTipoPago()};
            dtm1.addRow(fila);
            
    
         }if(dtm1.getRowCount()==0){
         mensaje.setText("No Se ayó Resultado  En La Busqueda para Las Ventas a: "+vistas.convertirMayuscula(txt_nombreC.getText())+" Del Dia: "+fecha+"");
         }else{
             mensaje.setText("");
         }
        } catch (Exception ex) {
            Logger.getLogger(VistaListaVentas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    private void ListarVentaMesCliente(String fecha,String fechaMes) {
        try {
            dtm1.setNumRows(0);
         ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
         mbd.conectar();          
         ControlVenta.con=mbd.getConexion();
         ControlVenta.listarVenta1("SELECT *FROM ventas where cliente='"+txt_mailC.getText()+"'");
         Iterator iter1= ControlVenta.getVenta().iterator();
         while(iter1.hasNext()){
            Venta ven = (Venta) iter1.next();
       jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Todas Las Ventas a: "+vistas.convertirMayuscula(ven.getCliente().getNombre()+" "+ven.getCliente().getApellido())+" Del Mes: "+fechaMes+""));
            StringTokenizer feMes=new StringTokenizer(ven.getFecha(),"/ ");
            String fDia=feMes.nextToken().toString();
            String fMes=feMes.nextToken().toString();
            String fAno=feMes.nextToken().toString();
            String FechaMes=fMes+"/"+fAno;
            if(FechaMes.equals(fechaMes)){
                    String[] fila = {ven.getNumero(),ven.getFecha(),ven.getCliente().getNombre(),(int)ven.getTotal()+"", ven.getUsuario().getNombre(),ven.getTipoPago()};
            dtm1.addRow(fila);
            }
    
         }if(dtm1.getRowCount()==0){
         mensaje.setText("No Se ayó Resultado  En La Busqueda Para Las Ventas a: "+vistas.convertirMayuscula(txt_nombreC.getText())+" Del Mes: "+fechaMes+"");
         }else{
             mensaje.setText("");
         }
        } catch (Exception ex) {
            Logger.getLogger(VistaListaVentas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    private void ListarVentaAnoCliente(String fecha,String fechaAno) {
        try {
            dtm1.setNumRows(0);
         ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
         mbd.conectar();          
         ControlVenta.con=mbd.getConexion();
         ControlVenta.listarVenta1("SELECT *FROM ventas where cliente='"+txt_mailC.getText()+"'");
         Iterator iter1= ControlVenta.getVenta().iterator();
         while(iter1.hasNext()){
            Venta ven = (Venta) iter1.next();
    jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Todas Las Ventas De "+vistas.convertirMayuscula(ven.getCliente().getNombre()+" "+ven.getCliente().getApellido())+" Del Año: "+fechaAno+""));
            StringTokenizer feMes=new StringTokenizer(ven.getFecha(),"/ ");
            String fDia=feMes.nextToken().toString();
            String fMes=feMes.nextToken().toString();
            String fAno=feMes.nextToken().toString();
            String FechaMes=fAno;
            if(FechaMes.equals(fechaAno)){
                     String[] fila = {ven.getNumero(),ven.getFecha(),ven.getCliente().getNombre(),(int)ven.getTotal()+"", ven.getUsuario().getNombre(),ven.getTipoPago()};
            dtm1.addRow(fila);
            }
    
         }if(dtm1.getRowCount()==0){
         mensaje.setText("No Se ayó Resultado  En La Busqueda Para Las Ventas Al Cliente: "+vistas.convertirMayuscula(txt_nombreC.getText())+" Del Año: "+fechaAno+"");
         }else{
             mensaje.setText("");
         }
        } catch (Exception ex) {
            Logger.getLogger(VistaListaVentas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    private void ListarVentaDiaUsuario(String fecha) {
        try {
            dtm1.setNumRows(0);
         ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
         mbd.conectar();          
         ControlVenta.con=mbd.getConexion();
         ControlVenta.listarVenta1("SELECT *FROM ventas WHERE fecha= '"+fecha+"' and vendedor='"+txt_mailC.getText()+"'");
         Iterator iter1= ControlVenta.getVenta().iterator()
                 ;
         while(iter1.hasNext()){
            Venta ven = (Venta) iter1.next();
            jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Todas Las Ventas Realizadas Por: "+vistas.convertirMayuscula(ven.getUsuario().getNombre()+" "+ven.getUsuario().getApellido())+" Del Dia: "+fecha+""));
           String[] fila = {ven.getNumero(),ven.getFecha(),ven.getCliente().getNombre(),(int)ven.getTotal()+"", ven.getUsuario().getNombre(),ven.getTipoPago()};
            dtm1.addRow(fila);
            
    
         }if(dtm1.getRowCount()==0){
         mensaje.setText("No Se ayó Resultado  En La Busqueda Para Las Ventas Realizadas Por: "+vistas.convertirMayuscula(txt_nombreC.getText())+" Del Dia: "+fecha+"");
         }else{
             mensaje.setText("");
         }
        } catch (Exception ex) {
            Logger.getLogger(VistaListaVentas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    private void ListarVentaMesUsuario(String fecha,String fechaMes) {
        try {
            dtm1.setNumRows(0);
         ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
         mbd.conectar();          
         ControlVenta.con=mbd.getConexion();
         ControlVenta.listarVenta1("SELECT *FROM ventas where vendedor='"+txt_mailC.getText()+"'");
         Iterator iter1= ControlVenta.getVenta().iterator();
         while(iter1.hasNext()){
            Venta ven = (Venta) iter1.next();
            jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Todas Las Ventas Realizadas Por: "+vistas.convertirMayuscula(ven.getUsuario().getNombre()+" "+ven.getUsuario().getApellido())+" Del Mes: "+fechaMes+""));
            StringTokenizer feMes=new StringTokenizer(ven.getFecha(),"/ ");
            String fDia=feMes.nextToken().toString();
            String fMes=feMes.nextToken().toString();
            String fAno=feMes.nextToken().toString();
            String FechaMes=fMes+"/"+fAno;
            if(FechaMes.equals(fechaMes)){
                     String[] fila = {ven.getNumero(),ven.getFecha(),ven.getCliente().getNombre(),(int)ven.getTotal()+"", ven.getUsuario().getNombre(),ven.getTipoPago()};
            dtm1.addRow(fila);
            }
    
         }if(dtm1.getRowCount()==0){
         mensaje.setText("No Se ayó Resultado  En La Busqueda Para Las Ventas Realizadas Por: "+vistas.convertirMayuscula(txt_nombreC.getText())+" Del Mes: "+fechaMes+"");
         }else{
             mensaje.setText("");
         }
        } catch (Exception ex) {
            Logger.getLogger(VistaListaVentas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    private void ListarVentaAnoUsuario(String fecha,String fechaAno) {
        try {
            dtm1.setNumRows(0);
         ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
         mbd.conectar();          
         ControlVenta.con=mbd.getConexion();
         ControlVenta.listarVenta1("SELECT *FROM ventas where vendedor='"+txt_mailC.getText()+"'");
         Iterator iter1= ControlVenta.getVenta().iterator();
         while(iter1.hasNext()){
            Venta ven = (Venta) iter1.next();
            jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Todas Las Ventas Realizadas Por: "+vistas.convertirMayuscula(ven.getUsuario().getNombre()+" "+ven.getUsuario().getApellido())+" Del Año: "+fechaAno+""));
            StringTokenizer feMes=new StringTokenizer(ven.getFecha(),"/ ");
            String fDia=feMes.nextToken().toString();
            String fMes=feMes.nextToken().toString();
            String fAno=feMes.nextToken().toString();
            String FechaMes=fAno;
            if(FechaMes.equals(fechaAno)){
                 String[] fila = {ven.getNumero(),ven.getFecha(),ven.getCliente().getNombre(),(int)ven.getTotal()+"", ven.getUsuario().getNombre(),ven.getTipoPago()};
            dtm1.addRow(fila);
            }
    
         }if(dtm1.getRowCount()==0){
         mensaje.setText("No Se ayó Resultado  En La Busqueda Para Las Ventas Realizadas Por: "+vistas.convertirMayuscula(txt_nombreC.getText())+" Del Año: "+fechaAno+"");
         }else{
             mensaje.setText("");
         }
        } catch (Exception ex) {
            Logger.getLogger(VistaListaVentas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    private void ListarVenta() {
        try {
            jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Todas Las Ventas "));
            dtm1.setNumRows(0);
         ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
         mbd.conectar();          
         ControlVenta.con=mbd.getConexion();
         ControlVenta.listarVenta1("SELECT *FROM ventas ");
         Iterator iter1= ControlVenta.getVenta().iterator();
         while(iter1.hasNext()){
            Venta ven = (Venta) iter1.next();
              String[] fila = {ven.getNumero(),ven.getFecha(),ven.getCliente().getNombre(),(int)ven.getTotal()+"", ven.getUsuario().getNombre(),ven.getTipoPago()};
            dtm1.addRow(fila);
            
    
         }if(dtm1.getRowCount()==0){
         mensaje.setText("No Se ayó Resultado  En La Busqueda De Las ventas");
         }else{
             mensaje.setText("");
         }
        } catch (Exception ex) {
            Logger.getLogger(VistaListaVentas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    private void ListarVentaCliente(String id) {
        try {
            dtm1.setNumRows(0);
         ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
         mbd.conectar();          
         ControlVenta.con=mbd.getConexion();
         ControlVenta.listarVenta1("SELECT *FROM ventas WHERE cliente='"+id+"'");
         Iterator iter1= ControlVenta.getVenta().iterator()
                 ;
         while(iter1.hasNext()){
            Venta ven = (Venta) iter1.next();
            jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Todas Las Ventas a: "+vistas.convertirMayuscula(ven.getCliente().getNombre()+" "+ven.getCliente().getApellido())));
            String[] fila = {ven.getNumero(),ven.getFecha(),ven.getCliente().getNombre(),(int)ven.getTotal()+"", ven.getUsuario().getNombre(),ven.getTipoPago()};
            dtm1.addRow(fila);       
    
         }if(dtm1.getRowCount()==0){
         mensaje.setText("No Se ayó Resultado  En La Busqueda Para El Cliente:"+txt_nombreC.getText()+"");
         }else{
             mensaje.setText("");
         }
        } catch (Exception ex) {
            Logger.getLogger(VistaListaVentas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
     private void ListarVentaUsuario(String id) {
        try {
            dtm1.setNumRows(0);
         ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
         mbd.conectar();          
         ControlVenta.con=mbd.getConexion();
         ControlVenta.listarVenta1("SELECT *FROM ventas WHERE vendedor ='"+id+"'");
         Iterator iter1= ControlVenta.getVenta().iterator()
                 ;
         while(iter1.hasNext()){
            Venta ven = (Venta) iter1.next();
            jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Todas Las Ventas Realizadas Por: "+vistas.convertirMayuscula(ven.getUsuario().getNombre()+" "+ven.getUsuario().getApellido())));
            String[] fila = {ven.getNumero(),ven.getFecha(),ven.getCliente().getNombre(),(int)ven.getTotal()+"", ven.getUsuario().getNombre(),ven.getTipoPago()};
            dtm1.addRow(fila);       
    
         }if(dtm1.getRowCount()==0){
         mensaje.setText("No Se ayó Resultado  En La Busqueda Para El Ususario:"+txt_nombreC.getText()+"");
         }else{
             mensaje.setText("");
         }
        } catch (Exception ex) {
            Logger.getLogger(VistaListaVentas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void Limpiar() {
          txt_nombreC.setText("Nombre Completo");
            txt_DireccionC.setText("Direccion");
            txt_telefonoC.setText("Telefono");
            txt_mailC.setText("Identificacion");
    }
  private void avririventana() {
        int x=listaventas.getSelectedRow();
       
    if(x<0){
    mensaje.setText("Selecione Primero LA Venta");
    }else{
            try {
        
                String e=dtm1.getValueAt(x,0).toString();
                Venta Ven=ControlVenta.BuscarVenta(e);
                iva.setText((int)Ven.getIva()+"");
                descuento.setText((int)Ven.getDescuento()+"");
                facturacredito.setText(ControlVenta.BuscarVenta(e).getNumero());
                fechacredito.setText(Ven.getFecha());
                saldoact.setText("$"+Ven.getTotal()+"");
                ListarProductos(e);
                idcliente.setText(Ven.getCliente().getId());
                txtcredito.setText(e);
                NombreCliente.setText(Ven.getCliente().getNombre()+" "+Ven.getCliente().getApellido());
                tipo.setText(Ven.getTipoPago());               
                Abono.setModal(true);
                Abono.setResizable(true);
                Abono.setSize(650,370);
                Abono.setLocationRelativeTo(this);
                Abono.setVisible(true);
                
            }
            catch (SQLException ex) {
                Logger.getLogger(VistaCreditos.class.getName()).log(Level.SEVERE, null, ex);
            }            // TODO add your handling code here:
            catch (Exception ex) {
                Logger.getLogger(VistaCreditos.class.getName()).log(Level.SEVERE, null, ex);
            }
    }    
    }
    private void ListarProductos(String factura) {
        
      try {
            dtm2.setNumRows(0);
            ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
            mbd.conectar();      
            ControlVenta.con = mbd.getConexion();
            ControlDetalleVenta.listarDetalleVenta1("SELECT dv.* FROM ventas v,productos p,detalleventas dv WHERE v.num='"+factura+"' AND  v.num=dv.venta AND p.codigo=dv.produto");
            Iterator it =  ControlDetalleVenta.getDetalleVenta().iterator();
                   while (it.hasNext()) {
                               DetalleVenta dv=(DetalleVenta) it.next();
                               int stm = (int) dv.getSubtotal();
                               int can = (int) dv.getCantidad();
                               int cact = (int) dv.getSubtotal();
                               int cant = (int) dv.getCantidad();
                               String[] fila = {dv.getProducto().getCodigo(),dv.getProducto().getNombre(),dv.getProducto().getDescripcion(), dv.getProducto().getPrecio()+"",can+"",stm+"",cact+"",cant+""};
                                 dtm2.addRow(fila);
              
                    }
        } catch (SQLException ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        }
                }
}
